﻿@{
    ViewBag.Title = "Create";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}

<html>
<head>
    <script type="text/javascript" src="~/Content/ckeditor/ckeditor.js"></script>
    <script type="text/javascript" src="~/Scripts/jquery.query.js"></script>
    <link href="~/Content/ckeditor/contents.css" type="text/css" rel="stylesheet" />
    <script type="text/javascript">
        $(function () {            
            var spId = $.query.get("id");            
            $('#ff').form('load', '/SitePage/GetSPById/?id=' + spId + '');
            $("#SitePageTitle").attr("disabled", true);
        });
         function savePage() {
            var editor = CKEDITOR.instances.SitePageBody;
            var bodydata = editor.getData();
            var postdata = {
                SitePageTitle: $("#SitePageTitle").val(),
                SitePageId: $("#SitePageId").val(),
                SitePageBody: bodydata
            };
            $.ajax({
                type: "POST",
                url: '/SitePage/UpdatePage',
                contentType: 'application/json; charset=utf-8',
                data: JSON.stringify(postdata),
                beforeSend: function () {
                    return $('#ff').form('validate');
                },
                success: function (result) {
                    if (result != "success") {
                        $.messager.show({
                            title: 'Error',
                            msg: result.errorMsg
                        });
                    } else {
                        //$.messager.alert("Message", "Successfully");
                        alert("Update Successfully");
                        location.href = "/SitePage/Index";
                    }
                }
            });
        }
    </script>
</head>
<body>
    <div class="easyui-panel" title="Site Page" style="height: 500px" iconCls="icon-ok">
        <div style="padding: 10px 0 10px 60px">
            <form id="ff" method="post">
                <input type="hidden" id="SitePageId" name="SitePageId"/>
                <table>
                    <tr>
                        <td nowrap>Page Title:</td>
                        <td>
                            <input class="easyui-validatebox" type="text" id="SitePageTitle" name="SitePageTitle"></input></td>
                    </tr>
                    <tr>
                        <td>Content:</td>
                        <td style="width: 100%">
                            <textarea id="SitePageBody" name="SitePageBody" cols="20" rows="5" class="ckeditor"></textarea></td>
                    </tr>
                    <tr>
                        <td colspan="2" style="text-align: center; padding-top: 10px">
                            <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" onclick="savePage()">Save</a>
                            <a href="/SitePage/Index" class="easyui-linkbutton" iconcls="icon-cancel">Cancel</a>
                        </td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
</body>
</html>
